package edu.kit.ksri.db.mturk.workerpools;

/**
 * Copyright (c) 2010-2011 Karlsruhe Institute of Technology (KIT), Germany
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 * 
 * --------------------------------------------------------------------------
 * 
 * Software: CSP/WMV tool for dynamic quality management of microtasks
 * http://www.ksri.kit.edu/Upload/Users/PeopleClouds/HCOMP2011_An_extendable_toolkit_for_managing_quality_of_human-based_eServices.pdf
 * 
 * Organization: Karlsruhe Institute of Technology (KIT), Germany
 * http://www.kit.edu
 * 
 * Project: PeopleClouds project of the Karlsruhe Service Research Institute(KSRI)
 * http://www.ksri.kit.edu/Default.aspx?PageId=818
 * 
 * Contributing authors: David Bermbach, Sandra Rath, Pascal Wichmann, Robert Kern
 * 
 * ---------------------------------------------------------------------------
 * 
 * Purpose: Represents an abstract pServices worker.
 * This class shall only incorporate scenario-INDEPENDENT properties and methods.
 * Scenario-specific child classes will inherit these general worker properties and methods.
 * 
 * Note: This class has a natural ordering that is inconsistent with equals.
 * Note: Children of this class must implement the serializable interface.
 */

public abstract class AbstractWorker implements Comparable<AbstractWorker> {

	/** the worker id */
	protected String workerId;

	/** the total number of assignments this worker has completed */
	protected int totalAssignments = 0;

	/** only used for synchronized blocks to avoid deadlocks */
	protected Boolean syncLockField = true;
	
	/** only to compare how good the workers are. 0 being the lowest and 100 being the highest score */
	protected double correctnessLevel = 100;

	/**
	 * @param workerId
	 */
	public AbstractWorker() {
		super();
	}

	@Override
	public abstract boolean equals(Object arg);
	
	/**
	 * 
	 * Children of AbstractWorker must declare this method as synchronized
	 * 
	 * @return a String [] version of all the fields of this worker. Is used for
	 *         CSV export of worker pools.    
	 */
	public abstract String[] toStringArray();

	public abstract int getTotalInspectedCorrect();
	
	public abstract int getTotalInspectedFalse();

	@Override
	public int hashCode() {
		return workerId.hashCode();
	}

	/**
	 * @return the workerId
	 */
	public String getWorkerId() {
		return this.workerId;
	}

	/**
	 * @return the totalAssignments
	 */
	public int getTotalAssignments() {
		return this.totalAssignments;
	}
	
	/**
	 * @return the correctnessLevel
	 */
	public double getCorrectnessLevel() {
		return correctnessLevel;
	}
	
}
